﻿@model PortalWeb.Models.Cms.ArticleViewModel
@{
    ViewBag.Title = "编辑";
}
@section scripts{
    <script type="text/javascript" src="~/Scripts/kindeditor-4.1.10/kindeditor-min.js"></script>
    <script type="text/javascript" src="~/Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript">
        //编辑框
        KindEditor.ready(function (K) {
            window.editor = K.create('#Content', {
                height: '500px',
                uploadJson: '@Url.Action("Upload", "Attachment")',
                fileManagerJson: '@Url.Action("FileManagerJson", "Attachment", new {id = @Model.Id})',
                allowFileManager: true,
                formatUploadUrl: false
            });
            //首页图片
            var editor2 = K.editor({
                fileManagerJson: '@Url.Action("FileManagerJson", "Attachment", new {id = @Model.Id})'
            });
            K('#btn_picselect').click(function() {
                editor2.loadPlugin('filemanager', function() {
                    editor2.plugin.filemanagerDialog({
                        viewType: 'VIEW',
                        dirName: 'image',
                        clickFn: function(url, title) {
                            var url;
                            $.ajax({
                                type: "post",
                                url: "@Url.Action("CreateThumbnail", "Attachment")",
                                data: { originalPicture: url },
                                async: false,
                                success: function(data) {
                                    if (data == null) alert("生成缩略图失败！");
                                    else {
                                        K('#CommonModel_DefaultPicUrl').val(data);
                                        K('#imgpreview').attr("src", data);
                                    }
                                    editor2.hideDialog();
                                }
                            });
                        }
                    });
                });
            });
        });
    </script>
}
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()

        <div class="form-horizontal">
            @Html.ValidationSummary(true)
            @Html.HiddenFor(model => model.Id)
            <div class="form-group">
                <label class="control-label col-sm-2" for="CategoryId">栏目</label>
                <div class="col-sm-10">
                    <input id="CategoryId" name="CategoryId"
                           data-options="url:'@Url.Action("JsonTree", "Category", new { model="Article" })'"
                           class="easyui-combotree" style="height: 34px; width: 280px;" value="@Model.CategoryId" />
                    @Html.ValidationMessageFor(model => model.CategoryId)
                </div>
                </div>
            </div>
            <div class="form-group">
                @Html.LabelFor(model => model.Title, new {@class = "control-label col-sm-2"})
                <div class="col-sm-10">
                    @Html.TextBoxFor(model => model.Title, new {@class = "form-control"})
                    @Html.ValidationMessageFor(model => model.Title)
                </div>
            </div>
            <div class="form-group">
                @Html.LabelFor(model => model.Author, new {@class = "control-label col-sm-2"})
                <div class="col-sm-10">
                    @Html.TextBoxFor(model => model.Author, new {@class = "form-control"})
                    @Html.ValidationMessageFor(model => model.Author)
                </div>
            </div>
            <div class="form-group">
                @Html.LabelFor(model => model.Source, new {@class = "control-label col-sm-2"})
                <div class="col-sm-10">
                    @Html.TextBoxFor(model => model.Source, new {@class = "form-control"})
                    @Html.ValidationMessageFor(model => model.Source)
                </div>
            </div>
            <div class="form-group">
                @Html.LabelFor(model => model.Intro, new {@class = "control-label col-sm-2"})
                <div class="col-sm-10">
                    @Html.TextAreaFor(model => model.Intro, new {@class = "form-control"})
                    @Html.ValidationMessageFor(model => model.Intro)
                </div>
            </div>
            <div class="form-group">
                @Html.LabelFor(model => model.Content, new {@class = "control-label col-md-2"})
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Content)
                    @Html.ValidationMessageFor(model => model.Content)
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.DefaultPicUrl, new {@class = "control-label col-sm-2"})
                <div class="col-sm-10">
                    <img id="imgpreview" class="thumbnail" src="" />
                    @Html.HiddenFor(model => model.DefaultPicUrl)
                    <a id="btn_picselect" class="easyui-linkbutton">选择…</a>
                    @Html.ValidationMessageFor(model => model.DefaultPicUrl)
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <input type="submit" value="保存" class="btn btn-default" />
                </div>
            </div>
        </div>
    }
